<?php
error_reporting("E_ERROR");


// standard Elgg module callse
elgg_register_event_handler('init','system','cas_auth_init');


//supprting functions

function cas_auth_init() {
  global $CONFIG;
    
  $root = dirname(__FILE__);
  
  elgg_register_library('elgg:cas_auth', "$root/lib/lib.php");
  
  // actions
  $action_path = "$root/actions/cas_auth";
  
  elgg_register_action('login', "$action_path/login.php",'public');
  
  elgg_register_action('logout', "$action_path/logout.php");
  
  register_pam_handler('cas_auth_authenticate');
 
  register_translations("$root/languages/");

}


function cas_auth_authenticate($credentials) {

	elgg_load_library('elgg:cas_auth');
	$config = elgg_get_calling_plugin_entity('cas_auth');
    // Perform the authentication
    return authCAS($config, $credentials);
}

?>